package com.leetcode.algorithm.y22.m06;

/**
 * 1572. 矩阵对角线元素的和
 * 
 * https://leetcode.cn/problems/matrix-diagonal-sum/
 * 
 * @author jie.deng
 *
 */
class Question1572Solution01 {
	
	public int diagonalSum(int[][] mat) {
		int len = mat.length;
		int sum = 0;
		for (int i = 0; i < len; i++) {
			sum += mat[i][i];
			sum += mat[i][len - 1 - i];
		}
		if ((len & 1) == 1) {
			sum -= mat[len >> 1][len >> 1];
		}
		return sum;
	}
    
}